package com.ruoyi.web.controller.loss;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.loss.domain.vo.WellLostDescribeVo;
import com.ruoyi.loss.domain.bo.WellLostDescribeBo;
import com.ruoyi.loss.service.IWellLostDescribeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 本井漏失描述
 *
 * @author toteny
 * @date 2024-01-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/loss/wellLostDescribe")
public class WellLostDescribeController extends BaseController {

    private final IWellLostDescribeService iWellLostDescribeService;

    /**
     * 查询本井漏失描述列表
     */
    @GetMapping("/list")
    public TableDataInfo<WellLostDescribeVo> list(WellLostDescribeBo bo, PageQuery pageQuery) {
        return iWellLostDescribeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出本井漏失描述列表
     */
    @Log(title = "本井漏失描述", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WellLostDescribeBo bo, HttpServletResponse response) {
        List<WellLostDescribeVo> list = iWellLostDescribeService.queryList(bo);
        ExcelUtil.exportExcel(list, "本井漏失描述", WellLostDescribeVo.class, response);
    }

    /**
     * 获取本井漏失描述详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<WellLostDescribeVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable Long id) {
        return R.ok(iWellLostDescribeService.queryById(id));
    }

    /**
     * 新增本井漏失描述
     */

    @Log(title = "本井漏失描述", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WellLostDescribeBo bo) {
        return toAjax(iWellLostDescribeService.insertByBo(bo));
    }

    /**
     * 修改本井漏失描述
     */

    @Log(title = "本井漏失描述", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WellLostDescribeBo bo) {
        return toAjax(iWellLostDescribeService.updateByBo(bo));
    }

    /**
     * 删除本井漏失描述
     *
     * @param ids 主键串
     */

    @Log(title = "本井漏失描述", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iWellLostDescribeService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
